//
//  SplashScreen.m
//  danpin
//
//  Created by lcb on 6/18/15.
//  Copyright (c) 2015 chuangjia. All rights reserved.
//

#import "SplashScreen.h"

@interface SplashScreen ()

@end

@implementation SplashScreen

- (void)dealloc{
    _splashImage = nil;
//    NSLog(@"%s", __PRETTY_FUNCTION__);
}

- (void)loadView{
    
    UIImageView *iv = [[UIImageView alloc] initWithImage:self.splashImage];
    iv.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    iv.contentMode = UIViewContentModeCenter;
    self.view = iv;
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    SEL didAppearSelector = @selector(splashScreenDidAppear:);
    if ([[self delegate] respondsToSelector:didAppearSelector]) {
        [[self delegate] splashScreenDidAppear:self];
    }
    [self performSelector:@selector(hide) withObject:nil afterDelay:0];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    if ([[self delegate] respondsToSelector:@selector(splashScreenWillDisappear:)]) {
        [[self delegate] splashScreenWillDisappear:self];
    }
}

- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    if ([[self delegate] respondsToSelector:@selector(splashScreenDidDisappear:)]) {
        [[self delegate] splashScreenDidDisappear:self];
    }
    self.splashImage = nil;
}

- (void)hide{
    if (self.showsStatusBarOnDismissal) {
        UIApplication *app = [UIApplication sharedApplication];
        [app setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - getter
- (UIImage *)splashImage{
    if (_splashImage == nil){
        self.splashImage = [UIImage imageNamed:@"Default.png"];
    }
    return _splashImage;
}


@end
